<?php 
	namespace Admin\Controller;
	use Admin\Model\AuthGroupModel;

	class TeamController extends AdminController{
		/*编辑操作*/
		public function editAc(){
			// var_dump($_POST);
			$editac = M('Team');
			$editac ->create();

			$id = $_POST['id'];


			// var_dump($_GET);
			$num = $editac ->where(array('id' => $id)) ->save();
			// var_dump($num);

			if ($num > 0 ) {
				$this ->redirect('Team/index','更改成功');
			}else{
				$this ->error('更新失败');
			}


			// $this ->display('Team/ht');
		}



		/*广告编辑*/
		public function edit(){
			// var_dump($_GET);
			$edit = M('Team');
			$data = $edit -> where(array('id'=>$_GET['id']))->select();
			// var_dump($data);

			$this ->assign('arr',$data);

			// var_dump($data);

			$this ->display('Team/edit');
		}







		public function index(){
			$arr = M('Team');
			// $arr= $ind ->field(array('path','a_lian','kname'))->select();


			// if(!empty($_GET['search'])){
			// 	$map['oname'] = array('like',"%".$_GET['search']."%"); 
	  //           $map1['oname'] = $_GET['search'];
			// }
			
			$count = $arr->where($map)->where($abc)->count();// 查询满足要求的总记录数
			// var_dump($arr);
			$Page = new \Think\Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数(10)
			$Page->setConfig('prev','上一页');
		    $Page->setConfig('next','下一页');
		    $Page->setConfig('last','末页');
		    $Page->setConfig('first','首页');
		    $Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
			$show = $Page->show();// 分页显示输出

			foreach($map1 as $key=>$val) {
	        	$Page->parameter[$key] = urlencode($val);
	        }


			// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
			// $data = $arr->order('id')->where($map)->where($abc)->limit($Page->firstRow.','.$Page->listRows)->select();
			$data = $arr->order('tid')->limit($Page->firstRow.','.$Page->listRows)->select();

			
			$this->assign('page',$show);// 赋值分页输出

			// var_dump($data);

			$this ->assign('arr',$data);
			$this ->display('Team/index');
		}
		


		/*批量删除操作*/
		public function delta(){
			$order= M('Team');
			$id= $_GET['u_id'];
			$id = rtrim($id,',');
			$num = explode(",",$id);
			// $c = explode(',',$b);

			// $result = $order->execute('delete from onethink_type where id in('.$list.')');
			// $map['id'] = array("in('$num')");
			// $model->where(array('id' => array('in',array(id1,id2,id3))));
			
			$result = $order ->where(array('id' => array('in',$num)))->delete();

			if($result){
				$data = array('status'=>true,'msg' =>'操作成功');
				$this ->ajaxReturn($data,'json');
			}else{
				$data = array('status'=>true,'msg' =>'操作失败');
				$this ->ajaxReturn($data,'json');
			}
		}



		/*信息删除操作*/
		public function del(){
			$order= M('Team');
			$id= $_GET['k_id'];
			if($order ->where(array('id'=>$id))->delete()){
				$data = array('status'=>true,'msg' =>'操作成功');

				$this ->ajaxReturn($data,'json');
			}else{
				die($data = array('status'=>true,'msg' =>'操作成功'));
			}
		}


		
		/*提交广告信息*/
		public function addAction(){
			// var_dump($_POST);
			if(!empty($_SESSION['gmid'])){
				$arr = M('Team');
				$num = $arr->where(array('status'=>'1'))->count();
				if ($num < 4) {
					$arr ->create();
					$gid = $_SESSION['gmid'];

					$res = $arr ->where(array('id'=>"$gid"))->save();
					// var_dump($res);
					// exit;
					if($res){
						// unset($_SESSION['gid']);
						$this->redirect('Team/index','上传成功');
					}else{
						$this ->error('上传失败');
					}
				}else{
					$_POST['status']='0';
					$arr ->create();
					$gid = $_SESSION['gmid'];

					$res = $arr ->where(array('id'=>"$gid"))->save();
					// var_dump($res);
					// exit;
					if($res){
						unset($_SESSION['gmid']);
						$this->redirect('Team/index','上传成功');
					}else{
						$this ->error('上传失败');
					}
				}

				

			}else{
					$this ->error('图片还未添加');
			}

				// $this ->display('Ad/ht');

		}







	/* 文件上传 */
    public function upload(){
		$return  = array('status' => 1, 'info' => '上传成功', 'data' => '');
		/* 调用文件上传组件上传文件 */
		$File = D('File');
		$file_driver = C('DOWNLOAD_UPLOAD_DRIVER');
		$info = $File->upload(
			$_FILES,
			C('DOWNLOAD_UPLOAD'),
			C('DOWNLOAD_UPLOAD_DRIVER'),
			C("UPLOAD_{$file_driver}_CONFIG")
		);

        /* 记录附件信息 */
        if($info){
            $return['data'] = think_encrypt(json_encode($info['download']));
            $return['info'] = $info['download']['name'];
        } else {
            $return['status'] = 0;
            $return['info']   = $File->getError();
        }

        /* 返回JSON数据 */
        $this->ajaxReturn($return);
    }

    /* 下载文件 */
    public function download($id = null){
        if(empty($id) || !is_numeric($id)){
            $this->error('参数错误！');
        }

        $logic = D('Download', 'Logic');
        if(!$logic->download($id)){
            $this->error($logic->getError());
        }

    }


	/**
     * 上传图片
     * @author huajie <banhuajie@163.com>
     */
	    public function uploadPicture(){
	        //TODO: 用户登录检测

	        /* 返回标准数据 */
	        $return  = array('status' => 1, 'info' => '上传成功', 'data' => '');

	        /* 调用文件上传组件上传文件 */
	        $Picture = D('Team');
	        $pic_driver = C('PICTURE_UPLOAD_DRIVER');
	        $info = $Picture->upload(
	            $_FILES,
	            C('PICTURE_UPLOAD'),
	            C('PICTURE_UPLOAD_DRIVER'),
	            C("UPLOAD_{$pic_driver}_CONFIG")
	        ); //TODO:上传到远程服务器

	        /* 记录图片信息 */
	        if($info){
	            $return['status'] = 1;
	            $return = array_merge($info['download'], $return);
	        } else {
	            $return['status'] = 0;
	            $return['info']   = $Picture->getError();
	        }

	        /* 返回JSON数据 */
	        $this->ajaxReturn($return);
	    }


	}




 ?>